<template>
    <div class="dialog people">
        <a-modal
            v-drag-modal
            class="completePeople"
            title="添加成果主要完成人"
            :visible="visible"
            :width="700"
            :maskClosable="false"
            @cancel="handleCancel"
            :footer="null"
        >
            <div class="dialogCont">
                <div class="btnList">
                    <a-button :disabled="is_modify=='Y'?false:true" @click="importPeople" type="primary" class="select">从已有人员选择</a-button>
                    <a-button @click="downloadtmp" class="templateDownload">模板下载</a-button>
                    <a-upload
                        name="file"
                        :multiple="false"
                        accept=".xlsx"
                        :fileList="importFileList"
                        :remove="handleRemove"
                        :customRequest="customRequest"
                    >
                        <a-button :disabled="is_modify=='Y'?false:true" style="background:#69C23A;color:#FFF;">
                            <a-icon type="upload" />
                            选择导入文件
                        </a-button>
                    </a-upload>
                </div>
                <div class="cont">
                    <div class="tableForm">
                        <table class="tableForm-1" style="text-align:center;" width="660" border="0" height="360" cellspacing="0" align="center" cellpadding="">
                            <tr>
                                <td width="90"><i>*</i>姓名</td>
                                <td width="130"><a-input v-model="form.name"/></td>
                                <td width="90"><i>*</i>完成人排序</td>
                                <td width="130">
                                    <!-- <a-input v-model="form.sort"/> -->
                                    <a-select class="selectList" default-value="" v-model="form.sort" style="width: 120px">
                                        <a-select-option v-for="index of maxNum" :value="index" :key="index">{{index}}</a-select-option>
                                    </a-select>
                                </td>
                                <td width="90"><i>*</i>性别</td>
                                <td width="130">
                                    <a-select class="selectList" default-value="" v-model="form.sex" style="width: 120px">
                                        <a-select-option v-for="(item, index) in sexArr" :value="item.value" :key="index">{{item.value}}</a-select-option>
                                    </a-select>
                                </td>
                            </tr>
                            <tr>
                                <td width="90">出生地</td>
                                <td width="130"><a-input v-model="form.bornAddress" /></td>
                                <td width="90"><i>*</i>民族</td>
                                <td width="130">
                                    <!-- <a-input v-model="form.nation" /> -->
                                    <a-select class="selectList" show-search option-filter-prop="children" :filter-option="filterOption" default-value="" v-model="form.nation" style="width: 120px">
                                        <a-select-option v-for="(item, index) in nation_data" :value="item.name" :key="index">{{item.name}}</a-select-option>
                                    </a-select>
                                </td>
                                <td width="90"><i>*</i>出生年月</td>
                                <td width="130">
                                    <a-date-picker type="date" v-model="form.bornTime" suffix-icon=" " @change="onBornTime" placeholder=""/>
                                    <!-- <a-input v-model="form.bornTime" /> -->
                                </td>
                            </tr>
                            <tr>
                                <!-- <td width="90">党派</td>
                                <td width="130"><a-input v-model="form.party" /></td> -->
                                <td width="90">行政职务</td>
                                <td width="130"><a-input v-model="form.xzzw"/></td>
                                <td width="90"><i>*</i>国籍</td>
                                <td width="130">
                                    <!-- <a-input v-model="form.country" /> -->
                                    <a-select class="selectList" default-value="" v-model="form.country" style="width: 120px">
                                        <a-select-option value="中国国籍">中国国籍</a-select-option>
                                        <a-select-option value="外国国籍">外国国籍</a-select-option>
                                    </a-select>
                                </td>
                                <td width="90"><i>*</i>{{form.country == '中国国籍' ? '身份证号' : '护照号'}}</td>
                                <td width="130"><a-input v-model="form.IDcard" /></td>
                            </tr>
                            <!-- <tr>
                                <td width="90">行政职务</td>
                                <td width="130"><a-input v-model="form.xzzw"/></td>
                                <td width="90"><i>*</i>归国党员</td>
                                <td width="130"><a-input v-model="form.ggdy"/></td>
                                <td width="90">归国时间</td>
                                <td width="130">
                                    <a-date-picker type="date" v-model="form.ggTime" suffix-icon=" " @change="onGgTime" placeholder=""/>
                                </td>
                            </tr> -->
                            <tr>
                                <td width="90"><i>*</i>工作单位</td>
                                <td colspan="3"><a-input v-model="form.gzdw" /></td>
                                <!-- <td width="90"><i>*</i>荣誉称号</td>
                                <td width="130"><a-input v-model="form.rych" /></td> -->
                                <!-- 阿发束带结发圣诞快乐放假ask的放假案例送快递放假啦 -->
                                <td width="90"><i></i>办公电话</td>
                                <td width="130">
                                    <a-input v-model="form.wcrBgdh" />
                                </td>
                            </tr>
                            <tr>
                                <td width="90"><i>*</i>通讯地址</td>
                                <td colspan="3"><a-input v-model="form.txdz" /></td>
                                <td width="90"><i></i>邮政编码</td>
                                <td width="130"><a-input v-model="form.yb" /></td>
                            </tr>
                            <tr>
                                <td width="90"><i>*</i>电子信箱</td>
                                <td colspan="3"><a-input v-model="form.dzyx" /></td>
                                <td width="90"><i>*</i>移动电话</td>
                                <td width="130"><a-input v-model="form.yddh" /></td>
                            </tr>
                            <tr>
                                <td width="90"><i>*</i>毕业学校</td>
                                <td width="130"><a-input v-model="form.byxx" /></td>
                                <td width="90"><i>*</i>文化程度</td>
                                <td width="130">
                                    <!-- <a-input v-model="form.whcd" /> -->
                                    <a-select class="selectList" default-value="" v-model="form.whcd" style="width: 120px">
                                        <a-select-option v-for="(item, index) in whcdArr" :value="item.value" :key="index">{{item.value}}</a-select-option>
                                    </a-select>
                                </td>
                                <td width="90"><i>*</i>最高学位</td>
                                <td width="130">
                                    <a-select class="selectList" default-value="" v-model="form.zgxw" style="width: 120px">
                                        <a-select-option v-for="(item, index) in zgxwArr" :value="item.value" :key="index">{{item.value}}</a-select-option>
                                    </a-select>
                                    <!-- <a-input v-model="form.zgxw" /> -->
                                </td>
                            </tr>
                            <tr>
                                <td width="90"><i>*</i>技术职称</td>
                                <td width="130"><a-input v-model="form.jszc" /></td>
                                <td width="90"><i>*</i>专业、专长</td>
                                <td width="130"><a-input v-model="form.zyzc" /></td>
                                <td width="90"><i></i>毕业时间</td>
                                <td width="130">
                                    <!-- <a-input v-model="form.bysj" /> -->
                                    <a-date-picker type="date" v-model="form.bysj" suffix-icon=" " @change="onBysj" placeholder=""/>
                                </td>
                            </tr>
                        </table>
                    </div>
                    <div class="describeUserInfo">
                        <h2>曾获奖励及荣誉称号情况(1000字以内)：</h2>
                        <a-textarea v-model="form.wcrChjj"/>
                    </div>
                    <div class="tableForm">
                        <table class="tableForm-2" style="text-align:center;" width="660" border="" height="40" cellspacing="0" align="center" cellpadding="">
                            <tr>
                                <td width="220"><i>*</i>参加本成果的起止时间</td>
                                <td width="90"><i>*</i>开始时间</td>
                                <td width="130">
                                    <a-date-picker
                                        type="date"
                                        :default-picker-value="moment(startTime, dateFormat)"
                                        :disabled-date="disabledStartDate"
                                        @openChange="handleStartOpenChange"
                                        v-model="form.wcrXmqssj"
                                        format="YYYY-MM-DD"
                                        suffix-icon=" "
                                        @change="onWcrXmqssj"
                                        placeholder=""
                                    />
                                </td>
                                <td width="90"><i>*</i>截止时间</td>
                                <td width="130">
                                    <a-date-picker
                                        :default-picker-value="moment(finishTime, dateFormat)"
                                        type="date"
                                        v-model="form.wcrXmjzsj"
                                        :disabled-date="disabledEndDate"
                                        @openChange="handleEndOpenChange"
                                        format="YYYY-MM-DD"
                                        suffix-icon=" "
                                        @change="onWcrXmjzsj"
                                        placeholder=""
                                    />
                                </td>
                            </tr>
                        </table>
                    </div>
                    <div class="contribution">
                        <h3><i>*</i>对本成果创新型贡献：</h3>
                        <p>本人在该项目创新工作中投入的工作量占本人同期工作总量的百分比为
                            <span>
                                <input type="text" v-model="form.wcrBfb">
                            </span>%。
                        </p>
                        <a-textarea v-model="form.wcrGx"/>
                    </div>
                    <div class="evidence">
                        <ul>
                            <li>
                                <span style="display:inline-block;">旁证资料</span>
                                <em style="display:block;color: #CB0C0C;font-style: normal;font-size: 14px;">(请上传pdf格式，50M以内)</em>
                            </li>
                            <li>
                                <a-button :disabled="type==1?true:false" class="templateDownload preview" @click="downloadFile">查看</a-button>

                                <a-upload
                                    accept=".pdf"
                                    name="file"
                                    :showUploadList="{showRemoveIcon:false}"
                                    :fileList="fileList"
                                    :customRequest="dataCustomRequest"
                                    :before-upload="beforeUpload"
                                    class="peopleFile"
                                >
                                    <a-button :disabled="is_modify=='Y'?false:true" class="uploadPeopleBtn" type="primary">上传</a-button>
                                </a-upload>
                            </li>
                            <li>
                                <p>项目成果前三完成人，其投入该项技术研究的工作量应占本人同期工作量的30%以上，同时须上传支持本人贡献成立的旁证材料，如直接支持核心发明成立的授权专利、公开发表的论文等。</p>
                            </li>
                        </ul>
                    </div>
                </div>
                <div class="btn" style="">
                    <a-button :disabled="is_modify=='Y'?false:true" html-type="submit" type="primary" style="width: 100px;height: 40px;margin:0 auto;" @click="handleOk">确定</a-button>
                </div>
            </div>
        </a-modal>
        <ImportCompletePeople :flag="importFlag" @handleImport="handleImport"/>
        <!-- <div class="showpdf" v-if="showpdf">
            <img class="closebtn pointer" @click="closepdf" src="@/assets/img/close1.png"/>
            <testPdf :cxj_cxj_id="cxj_cxj_id" :file-path="filePath"></testPdf>
        </div> -->
        <testPdf :cxj_cxj_id="cxj_cxj_id" :file-path="filePath" :showPdf="showpdf"></testPdf>
    </div>
</template>
<script>
import ImportCompletePeople from './importIndex';
import testPdf from '@/views/declarationSystem/declare/testPdf';
import XLSX from 'xlsx';
import dayjs from 'dayjs';
import moment from 'moment';
import {
    // 获取详情
    cxjsbWcrQueryById,
    cxjsb_downloadWcrmb,
    // 已报成果信息
    cxjsbGetCxjByid,
    // 完成人列表
    wcrListByCxjId
} from '@/api/shenbao';
export default {
    name: 'CompletePeopleUpdate',
    components:{
        ImportCompletePeople,
        testPdf
    },
    props: {
        flag: null,
        peopleId: null,
        type: null,
        is_modify: null,
        maxNum: null
    },
    watch: {
        flag(next, prev) {
            if (next != prev) {
                let self = this;
                self.visible = !self.visible;
                self.fetchCompletePeopleList();
                // setTimeout(()=>{
                //     console.log('2331231',self.is_modify)
                // },1000)
                if (self.type == 2) {
                    this.getDetailInfo(self.peopleId);
                }
            }
        }
    },
    data() {
        this.dateFormat = 'YYYY-MM-DD';
        return {
            importFileList: [],
            dataList: [],
            importFile: "",
            visible: false,
            importFlag: false,
            sexArr: [
                {
                    value: "男"
                },{
                    value: "女"
                }
            ],
            nation_data: [
                {id:1 ,name:'汉族'},
                {id:2 ,name:'蒙古族'},
                {id:3 ,name:'回族'},
                {id:4 ,name:'藏族'},
                {id:5 ,name:'维吾尔族'},
                {id:6 ,name:'苗族'},
                {id:7 ,name:'彝族'},
                {id:8 ,name:'壮族'},
                {id:9 ,name:'布依族'},
                {id:10,name:'朝鲜族'},
                {id:11,name:'满族'},
                {id:12,name:'侗族'},
                {id:13,name:'瑶族'},
                {id:14,name:'白族'},
                {id:15,name:'土家族'},
                {id:16,name:'哈尼族'},
                {id:17,name:'哈萨克族'},
                {id:18,name:'傣族'},
                {id:19,name:'黎族'},
                {id:20,name:'傈僳族'},
                {id:21,name:'佤族'},
                {id:22,name:'畲族'},
                {id:23,name:'高山族'},
                {id:24,name:'拉祜族'},
                {id:25,name:'水族'},
                {id:26,name:'东乡族'},
                {id:27,name:'纳西族'},
                {id:28,name:'景颇族'},
                {id:29,name:'柯尔克孜族'},
                {id:30,name:'土族'},
                {id:31,name:'达翰尔族'},
                {id:32,name:'么佬族'},
                {id:33,name:'羌族'},
                {id:34,name:'布朗族'},
                {id:35,name:'撒拉族'},
                {id:36,name:'毛南族'},
                {id:37,name:'仡佬族'},
                {id:38,name:'锡伯族'},
                {id:39,name:'阿昌族'},
                {id:40,name:'普米族'},
                {id:41,name:'塔吉克族'},
                {id:42,name:'怒族'},
                {id:43,name:'乌孜别克族'},
                {id:44,name:'俄罗斯族'},
                {id:45,name:'鄂温克族'},
                {id:46,name:'德昂族'},
                {id:47,name:'保安族'},
                {id:48,name:'裕固族'},
                {id:49,name:'京族'},
                {id:50,name:'塔塔尔族'},
                {id:51,name:'独龙族'},
                {id:52,name:'鄂伦春族'},
                {id:53,name:'赫哲族'},
                {id:54,name:'门巴族'},
                {id:55,name:'珞巴族'},
                {id:56,name:'基诺族'},
                {id:57,name:'其他'},
            ],
            whcdArr: [
                {
                    value: "博士"
                },{
                    value: "硕士"
                },{
                    value: "本科"
                },{
                    value: "大专"
                },{
                    value: "中专"
                }
            ],
            zgxwArr: [
                {
                    value: "博士"
                },{
                    value: "硕士"
                },{
                    value: "学士"
                }, {
                    value: '无'
                }],
            form: {
                name: '',
                sort: '',
                sex: '',
                bornAddress: '',
                nation: '', // 民族
                bornTime: '',//出身年月
                party: '', // 党派
                country: '',
                IDcard: '',
                xzzw: '', // 行政职务
                ggdy: '',
                ggTime: '',
                gzdw: '',
                rych: '',
                wcrBgdh: '',
                txdz: '',
                yb: '',
                dzyx: '',
                yddh: '',
                byxx: '',
                whcd: '',
                zgxw: '',
                jszc: '',
                zyzc: '',
                bysj: '',
                wcrChjj: '',
                wcrXmqssj: '',
                wcrXmjzsj: '',
                wcrBfb: '',
                wcrGx: '',
                file: ''
            },
            detailInfo: {},
            fileList: [],
            reg: /^1[3456789]\d{9}$/,
            yxreg: /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/,
            sfzreg: /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/,
            datereg: /^(\d{4})-(\d{2})-(\d{2})$/,
            startTime: '',
            finishTime: '',
            showpdf: false,
            cxj_cxj_id: '',
            filePath: '',
        }
    },
    mounted() {
        this.cxj_cxj_id = this.$route.query.cxj_cxj_id;
        this.getCxjsbGetCxjByid();
    },
    methods: {
        moment,
        fetchCompletePeopleList(){
            wcrListByCxjId({
                cxj_cxj_id: this.$route.query.cxj_cxj_id,
            }).then(res=>{
                let data = res.data;
                this.dataList = data.result;
            })
        },
        // 获取文件信息
        downloadFile(wcrPath){
            // console.log('detailInfo.wcrPath==', this.detailInfo.wcrPath)
            /* this.$router.push({
                path: '/shenbao/pdfFile',
                query: {
                    cxj_cxj_id: this.$route.query.cxj_cxj_id,
                    path: encodeURI(encodeURI(wcrPath))
                }
            }) */
            if (this.detailInfo && this.detailInfo.wcrPath) {
                this.showpdf = !this.showpdf;
                this.filePath = this.detailInfo.wcrPath;
                // let routeData = this.$router.resolve({
                //     path: '/shenbao/pdfFile',
                //     query: {
                //         cxj_cxj_id: this.$route.query.cxj_cxj_id,
                //         path: this.detailInfo.wcrPath
                //     }
                // });
                // window.open(routeData.href, '_blank');
            } else {
                this.$message.error('请上传附件')
            }
        },
        disabledStartDate(startValue) {
            // 开始时间
            const startTime = moment(this.startTime);
            console.log(startTime)
            // 截止时间
            const endTime = moment(this.finishTime);
            if (!startValue || !endTime) {
                return false;
            }
            return startValue.valueOf() <  startTime.valueOf() ||startValue.valueOf() > endTime.valueOf();
        },
      beforeUpload(file) {
        if (file) {
          if (file.size > 50*1024*1024) { // 此处判断上传文件的大小 , 单位为 b 故要乘以两个1024
            this.$message.warning('文件最大为50兆')
            this.fileList.
            return;
          } else if (file.type!='application/pdf') { // 此处判断上传文件的格式
            this.$message.warning('请上传pdf格式的文件')
            return;
          }
        }
      },
        disabledEndDate(endValue) {
            // const startValue = this.form.wcrXmqssj;
            // if (!endValue || !startValue) {
            //     return false;
            // }
            // return startValue.valueOf() >= endValue.valueOf();
            // 开始时间
            const startTime = moment(this.startTime);
            console.log(startTime)
            // 截止时间
            const endTime = moment(this.finishTime);
            if (!endValue || !endTime) {
                return false;
            }
            return endValue.valueOf() <  startTime.valueOf() ||endValue.valueOf() > endTime.valueOf();
        },
        handleStartOpenChange(open) {
            // if (!open) {
            //     this.endOpen = true;
            // }
        },
        handleEndOpenChange(open) {
            // this.endOpen = open;
        },
        getCxjsbGetCxjByid(){
            cxjsbGetCxjByid({
                cxj_cxj_id: this.$route.query.cxj_cxj_id
            }).then(res=>{
                let data = res.data;
                if (data.success) {
                    this.startTime = data.result.cxj_qssj.slice(0,10);
                    this.finishTime = data.result.cxj_wcsj.slice(0,10);
                }
            })
        },
        defaultValue() {
            return moment(this.startTime)
        },
        disabledDate(current) {
            // return current && current < this.startTime;
            return current < moment(this.startTime).endOf('day') || current > moment(this.finishTime).endOf('day') ;
        },

        // 通过覆盖默认的上传行为，可以自定义自己的上传实现
        customRequest(file){
            const that = this
            const fileReader = new FileReader()
            fileReader.onload = ev => {
                try {
                    const fileData = ev.target.result
                    const workbook = XLSX.read(fileData, {
                        type: 'binary'
                    })
                    const completePeopleInfo = workbook.SheetNames[0] // 取第一张表
                    const completePeopleInfoArr = XLSX.utils.sheet_to_json(workbook.Sheets[completePeopleInfo]) // 生成json表格内容
                    // console.log('表格内容', JSON.stringify(completePeopleInfoArr))
                    // console.log(completePeopleInfoArr[0].__EMPTY)
                    if (completePeopleInfoArr[13].__EMPTY_5 === "MB-CXJ-KJ-WCR") {
                        // console.log('ok')
                        that.ExcelInfo(completePeopleInfoArr)
                    } else {
                        // console.log('no')
                        that.$message.warning('模板错误，请从系统中下载模板！');
                    }
                    // 遍历SN放入Set集合 snSet
                    /* that.dataGrid.snSet.clear() // 清空一下之前的Set
                    completePeopleInfoArr.forEach(item => {
                        that.dataGrid.snSet.add(item.sn)
                    }) */
                    // 处理完SN列表之后可以开放OK按钮
                    this.enableSubmit = false
                } catch (e) {
                    return false
                }
            }
            fileReader.readAsBinaryString(file.file);
        },
        ExcelInfo(completePeopleInfoArr){
            // 姓名
            this.form.name = completePeopleInfoArr[0].__EMPTY;
            // 排序
            this.form.sort = completePeopleInfoArr[0].__EMPTY_2;
            // 性别
            this.form.sex = completePeopleInfoArr[0].__EMPTY_4;
            // 出生地
            this.form.bornAddress = completePeopleInfoArr[1].__EMPTY;
            // 民族
            this.form.nation = completePeopleInfoArr[1].__EMPTY_2;
            // 出生年月
            // this.form.bornTime = completePeopleInfoArr[1].__EMPTY_4;
            this.form.bornTime = completePeopleInfoArr[1].__EMPTY_4 ? dayjs(completePeopleInfoArr[1].__EMPTY_4).format('YYYY-MM-DD') : '';

            // 党派
            // this.form.party = data.result.wcrDp;
            // 国籍
            this.form.country = completePeopleInfoArr[2].__EMPTY_2;
            // 身份证号
            this.form.IDcard = completePeopleInfoArr[2].__EMPTY_4;
            // 行政职务
            this.form.xzzw = completePeopleInfoArr[2].__EMPTY;
            // 归国党员
            // this.form.ggdy = completePeopleInfoArr[0].__EMPTY;
            // 归国时间
            // this.form.ggTime = completePeopleInfoArr[0].__EMPTY;
            // 工作单位
            this.form.gzdw = completePeopleInfoArr[3].__EMPTY;
            // 荣誉称号
            // this.form.rych = completePeopleInfoArr[0].__EMPTY;
            // 办公电话
            this.form.wcrBgdh = completePeopleInfoArr[3].__EMPTY_4;
            // 通讯地址
            this.form.txdz = completePeopleInfoArr[4].__EMPTY;
            // 邮编
            this.form.yb = completePeopleInfoArr[4].__EMPTY_4;
            // 电子邮箱
            this.form.dzyx = completePeopleInfoArr[5].__EMPTY;
            // 移动电话
            this.form.yddh = completePeopleInfoArr[5].__EMPTY_4;
            // 毕业学校
            this.form.byxx = completePeopleInfoArr[6].__EMPTY;
            // 文化程度
            this.form.whcd = completePeopleInfoArr[6].__EMPTY_2;
            // 最高学位
            this.form.zgxw = completePeopleInfoArr[6].__EMPTY_4;
            // 技术职称
            this.form.jszc = completePeopleInfoArr[7].__EMPTY;
            // 专业、专长
            this.form.zyzc = completePeopleInfoArr[7].__EMPTY_2;
            // 毕业时间
            // this.form.bysj = completePeopleInfoArr[7].__EMPTY_4
            this.form.bysj = completePeopleInfoArr[7].__EMPTY_4 ? dayjs(completePeopleInfoArr[7].__EMPTY_4).format('YYYY-MM-DD') : '';

            // 个人简介及或奖励情况
            this.form.wcrChjj = completePeopleInfoArr[8].__EMPTY
            // 开始时间
            // this.form.wcrXmqssj = completePeopleInfoArr[9].__EMPTY
            this.form.wcrXmqssj = completePeopleInfoArr[9].__EMPTY ? dayjs(completePeopleInfoArr[9].__EMPTY).format('YYYY-MM-DD') : '';

            // 截止时间
            // this.form.wcrXmjzsj = completePeopleInfoArr[9].__EMPTY_3
            this.form.wcrXmjzsj = completePeopleInfoArr[9].__EMPTY_3 ? dayjs(completePeopleInfoArr[9].__EMPTY_3).format('YYYY-MM-DD')  : ''

            // 本成果创新型贡献
            this.form.wcrGx = completePeopleInfoArr[10].__EMPTY
            // 本成果创新型贡献百分比
            this.form.wcrBfb = completePeopleInfoArr[11].__EMPTY_4
        },
        handleRemove(file) {
            const index = this.importFileList.indexOf(file);
            const newFileList = this.importFileList.slice();
            newFileList.splice(index, -1);
            this.importFileList = newFileList
        },
        handleImport(id){
            this.getDetailInfo(id);
        },
        dataCustomRequest(file){
            let fileList = [...this.fileList, file.file]
            this.fileList = fileList.slice(-1);
            this.form.file = this.fileList[0];
            return false;
        },
        filterOption(input, option) {
            return (
                option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
            );
        },
        // 获取详情
        getDetailInfo(id){
            cxjsbWcrQueryById({
                cxj_cxj_id: this.$route.query.cxj_cxj_id,
                id: id
            }).then(res=>{
                let data = res.data;
                if (data.success) {
                    this.detailInfo = data.result;
                    // 姓名
                    this.form.name = data.result.wcrXm;
                    // 排序
                    this.form.sort = data.result.wcrXh;
                    // 性别
                    this.form.sex = data.result.wcrXb;
                    // 出生地
                    this.form.bornAddress = data.result.wcrCsd;
                    // 民族
                    this.form.nation = data.result.wcrMz;
                    // 出生年月
                    this.form.bornTime = data.result.wcrCsrq;
                    // 党派
                    // this.form.party = data.result.wcrDp;
                    // 国籍
                    this.form.country = data.result.wcrGj;
                    // 身份证号
                    this.form.IDcard = data.result.wcrSfzh;
                    // 行政职务
                    this.form.xzzw = data.result.wcrXzzw;
                    // 归国党员
                    // this.form.ggdy = data.result.wcrSfgg;
                    // 归国时间
                    // this.form.ggTime = data.result.wcrGgsj;
                    // 工作单位
                    this.form.gzdw = data.result.wcrGzdw;
                    // 荣誉称号
                    // this.form.rych = data.result.wcrRych;
                    // 办公电话
                    this.form.wcrBgdh = data.result.wcrBgdh;
                    // 通讯地址
                    this.form.txdz = data.result.wcrTxdz;
                    // 邮编
                    this.form.yb = data.result.wcrYb;
                    // 电子邮箱
                    this.form.dzyx = data.result.wcrYx;
                    // 移动电话
                    this.form.yddh = data.result.wcrZzdh;
                    // 毕业学校
                    this.form.byxx = data.result.wcrByxx;
                    // 文化程度
                    this.form.whcd = data.result.wcrWhcd;
                    // 最高学位
                    this.form.zgxw = data.result.wcrZgxw;
                    // 技术职称
                    this.form.jszc = data.result.wcrZc;
                    // 专业、专长
                    this.form.zyzc = data.result.wcrZy;
                    // 毕业时间
                    this.form.bysj = data.result.wcrBysj
                    // 个人简介及或奖励情况
                    this.form.wcrChjj = data.result.wcrChjj
                    // 开始时间
                    this.form.wcrXmqssj = data.result.wcrXmqssj
                    // 截止时间
                    this.form.wcrXmjzsj = data.result.wcrXmjzsj
                    // 本成果创新型贡献百分比
                    this.form.wcrBfb = data.result.wcrBfb
                    // 本成果创新型贡献
                    this.form.wcrGx = data.result.wcrGx
                    // 文件上传
                    this.form.file = data.result.wcrPath;
                    this.fileList = [];
                    let fileName = data.result.wcrPath.split('/');
                    this.fileList.push({
                        uid: data.result.id,    // 文件唯一标识，建议设置为负数，防止和内部产生的 id 冲突
                        name: fileName[2],   // 文件名
                        status: 'done', // 状态有：uploading done error removed
                        response: '{"status": "success"}', // 服务端响应内容
                    })
                }
            })
        },
        closepdf() {
            this.filePath = '';
            this.showpdf = false;
        },
        handleOk(e) {
            if (!this.form.name) {
                this.$message.warning('请填写姓名');
                return;
            }
            if (!this.form.sort) {
                this.$message.warning('请填写完成人排序');
                return;
            }
            if (!this.form.sex) {
                this.$message.warning('请填写性别');
                return;
            }
            if (!this.form.nation) {
                this.$message.warning('请填写民族');
                return;
            }
            if (!this.form.bornTime) {
                this.$message.warning('请填写出生年月');
                return;
            }
            if (!this.datereg.test(this.form.bornTime)) {
                this.$message.warning('请填写正确的出生年月格式');
                return;
            }
            if (!this.form.country) {
                this.$message.warning('请填写国籍');
                return;
            }
            const isChineseNationality = this.form.country === '中国国籍';
            const idCardMessage = isChineseNationality ? '身份证号' : '护照号';
            const idCardValue = this.form.IDcard;
            if (!idCardValue) {
                this.$message.warning(`请填写${idCardMessage}`);
                return;
            }
            if (isChineseNationality && !this.sfzreg.test(idCardValue)) {
                this.$message.warning('身份证号格式不正确');
                return;
            }
            // if (!this.form.ggdy) {
            //     this.$message.warning('请填写归国党员');
            //     return;
            // }
            if (!this.form.gzdw) {
                this.$message.warning('请填写工作单位');
                return;
            }
            // if (!this.form.rych) {
            //     this.$message.warning('请填写荣誉称号');
            //     return;
            // }
            if (!this.form.txdz) {
                this.$message.warning('请填写通讯地址');
                return;
            }
            // if (!this.form.yb) {
            //     this.$message.warning('请填写邮编');
            //     return;
            // }
            if (!this.form.dzyx) {
                this.$message.warning('请填写电子邮箱');
                return;
            }
            if (!this.yxreg.test(this.form.dzyx)) {
                this.$message.warning('邮箱格式不正确');
                return
            }
            if (!this.form.yddh) {
                this.$message.warning('请填写移动电话');
                return;
            }
            if (!this.reg.test(this.form.yddh)) {
                this.$message.warning('手机号格式不正确');
                return
            }
            if (!this.form.byxx) {
                this.$message.warning('请填写毕业学校');
                return;
            }
            if (!this.form.whcd) {
                this.$message.warning('请填写文化程度');
                return;
            }
            if (!this.form.zgxw) {
                this.$message.warning('请填写最高学位');
                return;
            }
            if (!this.form.jszc) {
                this.$message.warning('请填写技术职称');
                return;
            }
            if (!this.form.zyzc) {
                this.$message.warning('请填写专业、专长');
                return;
            }
            // if (!this.form.bysj) {
            //     this.$message.warning('请填写毕业时间');
            //     return;
            // }
            if (this.form.bysj){
              if (!this.datereg.test(this.form.bysj)) {
                  this.$message.warning('请填写正确的毕业时间格式');
                  return;
              }
            }
            if (!this.form.wcrXmqssj) {
                this.$message.warning('请填写开始时间');
                return;
            }
            if (!this.datereg.test(this.form.wcrXmqssj)) {
                this.$message.warning('请填写正确的开始时间格式');
                return;
            }
            if (!this.form.wcrXmjzsj) {
                this.$message.warning('请填写截止时间');
                return;
            }
            if (!this.datereg.test(this.form.wcrXmjzsj)) {
                this.$message.warning('请填写正确的截止时间格式');
                return;
            }
            if (!this.form.wcrBfb) {
                this.$message.warning('请填写本成果创新型贡献百分比');
                return;
            }
            if (this.form.sort == '1' || this.form.sort=='2' || this.form.sort=='3') {
                if (Number(this.form.wcrBfb)<30) {
                    this.$message.warning('成果创新型贡献百分比必须大于30%');
                    return;
                }
            }
            if (!this.form.wcrGx) {
                this.$message.warning('请填写本成果创新型贡献');
                return;
            }
            if (this.form.sort == '1' || this.form.sort=='2' || this.form.sort=='3') {
                if (!this.form.file) {
                    this.$message.warning('请上传文件');
                    return;
                }
            }

            let formData = new FormData();
            // 完成人id
            if (this.type == 1) {
                formData.append('id', '');
            } else if (this.type == 2) {
                formData.append('id', this.detailInfo.id);
            }
            // 姓名
            formData.append('wcrXm', this.form.name)
            // 完成人排序
            formData.append('wcrXh', this.form.sort)
            // 性别
            formData.append('wcrXb', this.form.sex)
            // 出生地
            formData.append('wcrCsd', this.form.bornAddress?this.form.bornAddress:'')
            // 民族
            formData.append('wcrMz', this.form.nation)
            // 出生年月
            formData.append('wcrCsrq', this.form.bornTime)
            // 党派
            // formData.append('wcrDp', this.form.party)
            // 国籍
            formData.append('wcrGj', this.form.country)
            // 身份证号
            formData.append('wcrSfzh', this.form.IDcard)
            // 行政职务
            formData.append('wcrXzzw', this.form.xzzw?this.form.xzzw:'')
            // 归国党员
            // formData.append('wcrSfgg', this.form.ggdy)
            // 归国时间
            // formData.append('wcrGgsj', this.form.ggTime)
            // 工作单位
            formData.append('wcrGzdw', this.form.gzdw)
            // 荣誉称号
            // formData.append('wcrRych', this.form.rych)
            // 办公电话
            formData.append('wcrBgdh', this.form.wcrBgdh?this.form.wcrBgdh:'')
            // 通讯地址
            formData.append('wcrTxdz', this.form.txdz)
            // 邮编
            formData.append('wcrYb', this.form.yb?this.form.yb:'')
            // 电子邮箱
            formData.append('wcrYx', this.form.dzyx)
            // 移动电话
            formData.append('wcrZzdh', this.form.yddh)
            // 毕业学校
            formData.append('wcrByxx', this.form.byxx)
            // 文化程度
            formData.append('wcrWhcd', this.form.whcd)
            // 最高学位
            formData.append('wcrZgxw', this.form.zgxw)
            // 技术职称
            formData.append('wcrZc', this.form.jszc)
            // 专业、专长
            formData.append('wcrZy', this.form.zyzc)
            // 毕业时间
            formData.append('wcrBysj', this.form.bysj?this.form.bysj:'')
            // 个人简介及或奖励情况
            formData.append('wcrChjj', this.form.wcrChjj?this.form.wcrChjj:'')
            // 开始时间
            formData.append('wcrXmqssj', this.form.wcrXmqssj)
            // 截止时间
            formData.append('wcrXmjzsj', this.form.wcrXmjzsj)
            // 本成果创新型贡献百分比
            formData.append('wcrBfb', this.form.wcrBfb)
            // 本成果创新型贡献
            formData.append('wcrGx', this.form.wcrGx)
            // 文件上传
            formData.append('file', this.form.file)
            this.$emit('handelComplatePeople', formData, this.$route.query.cxj_cxj_id)
        },
        onBornTime(date, dateString){
            this.form.bornTime = dateString;
        },
        onGgTime(date, dateString){
            this.form.ggTime = dateString;
        },
        onBysj(date, dateString){
            this.form.bysj = dateString;
        },
        onWcrXmqssj(date, dateString){
            this.form.wcrXmqssj = dateString;
        },
        onWcrXmjzsj(date, dateString){
            this.form.wcrXmjzsj = dateString;
        },
        handleCancel(e) {
            this.visible = false;
            this.fileList = [];
            this.form = {
                name: '',
                sort: '',
                sex: '',
                bornAddress: '',
                nation: '', // 民族
                bornTime: '',//出身年月
                party: '', // 党派
                country: '',
                IDcard: '',
                xzzw: '', // 行政职务
                ggdy: '',
                ggTime: '',
                gzdw: '',
                rych: '',
                wcrBgdh: '',
                txdz: '',
                yb: '',
                dzyx: '',
                yddh: '',
                byxx: '',
                whcd: '',
                zgxw: '',
                jszc: '',
                zyzc: '',
                bysj: '',
                wcrChjj: '',
                wcrXmqssj: '',
                wcrXmjzsj: '',
                wcrBfb: '',
                wcrGx: ''
            }
        },
        // 导入主要完成人
        importPeople(){
            this.importFlag = !this.importFlag;
        },
        downloadtmp() {
            let that = this;
            cxjsb_downloadWcrmb({
                cxj_cxj_id: this.$route.query.cxj_cxj_id,
            }).then(res=>{
                // console.log(res, 'res')
                that.downfn("主要完成人模板", res)
            })
        },
        downfn(title, res) {
            const data = res.data;
            const url = window.URL.createObjectURL(new Blob([data], {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}))
            const link = document.createElement('a')
            link.style.display = 'none'
            link.href = url;
            link.setAttribute('download', title+'.xlsx')
            document.body.appendChild(link)
            link.click()
            document.body.removeChild(link)
        }
    }
}
</script>
<style lang="less">
.peopleFile {
    .ant-upload-list {
        width: 150px;
        margin-left: -80px;
    }
}
.completePeople {
    .ant-modal{
        width: 1000px!important;
        .ant-modal-content {
            width: 1000px!important;
            max-height: 750px!important;
        }
    }
}


    .uploadPeopleBtn,.preview {
        padding: 0!important;
        width: 60px!important;
        // line-height:40px!important;
        // height: 40px!important;
        border: 1px solid #ECEBEB!important;
    }
    .btn {
        width:100%;
        text-align: center;
        padding: 20px 0;
        position: absolute;
        bottom: 0;
        left: 0;
        background: #fff;
    }
    td {
        input {
            width: 100%;
            height: 100%;
            border: 0;
            outline: 0;
        }
    }
    .ant-select-selection {
        border: 0;
    }
    .ant-select-selection__rendered {
        margin-left: 0;
        line-height: 40px;
    }
    .ant-select, .ant-select-selection, .ant-select-selection__rendered {
        width: 100%!important;
        height: 100%!important;
    }
    .ant-select-selection-selected-value {
        padding-left: 11px;
        color: #333;
        font-size: 14px;
    }
    .ant-calendar-picker {
        width: 100%;
        height: 100%;
        div {
            width: 100%;
            height: 100%;
            input {
                width: 100%;
                height: 100%;
                border: 0;
                outline: 0;
            }
        }
    }
</style>
<style lang="less" scoped>
    .cont {
        // width: 660px;
        border: 1px solid #ECEBEB;
        margin-top: 11px;
        margin-bottom: 80px;
    }
    .btnList {
        display: flex;
        button {
            margin-right: 7px;
            span {
                font-size: 14px;
                font-family: PingFangSC-Regular, PingFang SC;
                font-weight: 400;
                color: #FFFFFF;
                line-height: 20px;
            }
            &.import {
                width: 70px;
                height: 32px;
                background: #69C23A;
                border: 1px solid #69C23A;
            }
            &.templateDownload {
                span {
                    font-size: 14px;
                    font-family: PingFangSC-Regular, PingFang SC;
                    font-weight: 400;
                    color: #333333;
                    // line-height: 20px;
                }
            }
        }
    }

    .tableForm {
        table {
            width: 100%;
            border: 1px solid #ECEBEB;
            border-top: 0;
            border-left: 0;
            border-right: 0;
            tr {
                height: 40px;
                td {
                    border: 1px solid #ECEBEB;
                    color: #333333;
                    font-size: 14px;
                    font-weight: 400;

                    i {
                        color: #CB0C0C;
                        margin-right: 5px;
                    }
                    input {
                        width: 100%;
                        height: 100%;
                        border: 0;
                        outline: 0;
                    }
                }
            }
        }
        .tableForm-1 {
            tr {
                &:first-child {
                    td {
                        border-top: 0;
                    }
                }
                td {
                    &:first-child {
                        border-left: 0;
                    }
                    &:last-child {
                        border-right: 0;
                    }
                }
            }
        }
        .tableForm-2 {
            margin-top: 11px;
            td {
                &:first-child {
                    border-left: 0;
                }
                &:last-child {
                    border-right: 0;
                }
            }
        }
    }
    .describeUserInfo {
        h2 {
            width: 100%;
            margin: 0;
            padding-top: 15px;
            padding-bottom: 10px;
            padding-left: 8px;
            font-size: 14px;
            font-family: PingFangSC-Medium, PingFang SC;
            font-weight: 500;
            color: #333333;
            line-height: 20px;
        }
        textarea {
            margin-left: 1%;
            width: 98%;
            height: 68px!important;
            border: 1px solid #ECEBEB;
        }
    }
    .contribution {
        padding-top: 15px;
        h3 {
            padding-bottom: 13px;
            padding-left: 8px;
            i {
                color: #CB0C0C;
                margin-right: 5px;
            }
            font-size: 14px;
            font-family: PingFangSC-Medium, PingFang SC;
            font-weight: 500;
            color: #333333;
            line-height: 20px;
        }
        p {
            padding-left: 8px;
            margin-bottom: 10px;
            font-size: 14px;
            font-family: PingFangSC-Regular, PingFang SC;
            font-weight: 400;
            color: #333333;
            line-height: 20px;
            span {
                display: inline-block;
                border-bottom: 1px solid #333;
                width: 34px;
                background: red;
                input {
                    width: 34px;
                    border: 0;
                    outline: 0;
                    text-align: center;
                }
            }
        }
        textarea {
            margin-left: 1%;
            width: 98%;
            height: 68px!important;
            border: 1px solid #ECEBEB;
        }
    }
    .evidence {
        margin-top: 11px;
        margin-bottom: 15px;
        width: 100%;
        height: 77px;
        border-top: 1px solid #ECEBEB;
        border-bottom: 1px solid #ECEBEB;
        ul {
            display: flex;
            width: 100%;
            height: 77px;
            li {
                &:first-child {
                    width: 30%;
                    text-align: center;
                    // line-height: 77px;
                    border-right: 1px solid #ECEBEB;
                }
                &:last-child {
                    display: flex;
                    align-items: center;
                    justify-content: center;
                }
                &:nth-child(2) {
                    width: 150px;
                    // background: red;
                    display: flex;
                    padding-top: 10px;
                    // align-items: center;
                    border-right: 1px solid #ECEBEB;
                    button {
                        margin-right: 10px;
                        &:first-child {
                            margin-left: 10px;
                        }
                    }
                }
                span {
                    font-size: 14px;
                    font-family: PingFangSC-Regular, PingFang SC;
                    font-weight: 400;
                    color: #333333;
                    line-height: 20px;
                }
                p {
                    font-size: 12px;
                    font-family: PingFangSC-Regular, PingFang SC;
                    font-weight: 400;
                    color: #CB0C0C;
                    line-height: 20px;
                    padding: 0 15px;
                }
            }
        }
    }
</style>
